package org.example.common;

import com.seaway.models.sec06.*;
import io.grpc.ManagedChannelBuilder;
import io.grpc.stub.StreamObserver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author Administrator
 */
public class GrpcClient2 {
    private static final Logger LOG = LoggerFactory.getLogger(GrpcServer.class);

    private static void transfer() throws InterruptedException {
        var channel = ManagedChannelBuilder
                .forAddress("localhost", 5555)
                .usePlaintext()
                .build();

        var transferServiceStub = BankServiceGrpc.newBlockingStub(channel);
        for (int i = 0; i < 100; i++) {
            TimeUnit.SECONDS.sleep(1);
            try{
                var rest = transferServiceStub.getAccountBalance(BalanceCheckRequest.newBuilder().setAccountNumber(1).build());
                System.out.println("====>>>> " + rest.getBalance());
            }catch (Exception e){
                System.out.println(e.getMessage());
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        transfer();
    }
}
